home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0069_More Prime Numbers.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  616b  |  20 lines

  1.  
  2. Function CheckPrime(a : integer) : boolean;
  3. Var
  4.   x : integer;
  5.   y : integer;
  6. Begin
  7.   y:=0;
  8.   for x:=1 to (a div 2) do  {Only #s up to half of a can be factors}
  9.   begin
  10.     if (a mod x)=0 then y:=(y+1)
  11.   end;
  12.   if y=2 then checkprime:=true else checkprime:=false;
  13.   if a=1 then checkprime:=true;
  14. End;
  15.  
  16. You see, only prime numbers have exactly two factors, themselves and one.
  17. With the exception of One.  Therefore you have a specific IF for the
  18. number one.  One is prime, yet its only factor is one.  I think - Is one
  19. prime or not?  Anyway, remove that line if it isn't, the function will work.
  20.